import {createRouter, createWebHistory} from "vue-router";
import User from '@/views/user/user'
import EditUser from '@/views/user/edit'
import Commodity from "@/views/commodity/commodity";
import Category from "@/views/category/category";
import Plate from "@/views/plate/plate";
import School from "@/views/school/school";
import ConfessionalWall from "@/views/confessionalWall/confessionalWall";
import ConfessionalWallDetail from '@/views/confessionalWall/detail'
import ConfessionalWallExamine from '@/views/confessionalWall/examine'
import LostFoundItem from "@/views/lostFoundItem/lostFoundItem";
import LostFoundItemExamine from '@/views/lostFoundItem/examine'
import LostFoundItemDetail from '@/views/lostFoundItem/detail'
import Menu from '@/views/system/menu/index'
import Admin from '@/views/system/admin/index'
import Role from '@/views/system/role/index'
import CommodityExamine from '@/views/commodity/examine'
import CommodityDetail from '@/views/commodity/detail'
import TreeHoleCircle from '@/views/treeHole/circle'
import TreeHoleCircleDetail from '@/views/treeHole/circleDetail'
import TreeHoleDynamic from '@/views/treeHole/dynamic'
import TreeHoleDynamicExamine from '@/views/treeHole/dynamicExamine'
import TreeHoleDynamicDetail from '@/views/treeHole/dynamicDetail'
import CommentReportType from "@/views/commentReport/commentReportType";
import CommentReportList from "@/views/commentReport/commentReport";
import CommentReportDetail from '@/views/commentReport/detail'
import CommentReportExamine from '@/views/commentReport/examine'
import FeedbackRecordType from "@/views/feedbackRecordType/feedbackRecordType";
import FeedbackRecord from "@/views/feedbackRecord/feedbackRecord";
import HeadlineNews from "@/views/headlineNews";
import HeadlineNewsDetail from '@/views/headlineNews/detail'
import UpdateLog from '@/views/updateLog/index'
import ChatRoomIndex from '@/views/chatRoom/index'
import ChatHistory from "@/views/chatRoom/chatHistory";
import Carousel from "@/views/carousel";
import ContactAdmin from '@/views/contactAdmin/index'
import {getUserInfo} from "@/utils/auth";

const routes = [
    {
        path: '/',
        name: 'layout',
        component: () => import("../views/Layout"),
        redirect: "/index",
        children: [
            {
                path: '/index',
                name: 'index',
                component: () => import("../views/index.vue"),
                meta: {title: '首页', roleEncode: ['superAdmin']},
            },
        ]
    },
    {
        path: '/login',
        name: 'login',
        component: () => import("../views/login.vue"),
        meta: {title: '登录'}
    },
    {
        path: '/404',
        name: '404',
        hidden: true,
        component: () => import("../views/404")
    },
    {
        path: '/:pathMatch(.*)',
        redirect: '/404',
        hidden: true,
    }
]
const routerMap = {
    user: User,
    editUser: EditUser,
    commodity: Commodity,
    category: Category,
    school: School,
    confessionalWall: ConfessionalWall,
    confessionalWallDetail: ConfessionalWallDetail,
    confessionalWallExamine: ConfessionalWallExamine,
    lostFoundItem: LostFoundItem,
    lostFoundItemExamine: LostFoundItemExamine,
    lostFoundItemDetail: LostFoundItemDetail,
    plate: Plate,
    admin: Admin,
    role: Role,
    menu: Menu,
    commodityExamine: CommodityExamine,
    commodityDetail: CommodityDetail,
    treeHoleCircle: TreeHoleCircle,
    treeHoleCircleDetail: TreeHoleCircleDetail,
    treeHoleDynamic: TreeHoleDynamic,
    treeHoleDynamicExamine: TreeHoleDynamicExamine,
    treeHoleDynamicDetail: TreeHoleDynamicDetail,
    commentReportType: CommentReportType,
    commentReportList: CommentReportList,
    commentReportDetail: CommentReportDetail,
    commentReportExamine: CommentReportExamine,
    feedbackRecordType: FeedbackRecordType,
    feedbackRecord: FeedbackRecord,
    headlineNews: HeadlineNews,
    headlineNewsDetail: HeadlineNewsDetail,
    updateLog: UpdateLog,
    chatRoom: ChatRoomIndex,
    chatHistory: ChatHistory,
    carousel: Carousel,
    contactAdmin: ContactAdmin
}
if (getUserInfo()) {
    const menuVOS = getUserInfo().menuVOS
    const routerFunction = () => {
        menuVOS.forEach(menu => {
            if (menu.isRouter) {
                menu.component = routerMap[menu.componentName]
                routes[0].children.push(menu)
            }
        })
    }
    routerFunction()
}
//根据路由规则创建路由
const router = createRouter({
    history: createWebHistory("/"),
    routes,
});
export default router;
